/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package br.com.clicarros.processos;

import br.com.clicarros.processos.perfil.MontarPerfil;
import org.quartz.CronScheduleBuilder;
import org.quartz.JobBuilder;
import org.quartz.JobDetail;
import org.quartz.Scheduler;
import org.quartz.SchedulerFactory;
import org.quartz.Trigger;
import org.quartz.TriggerBuilder;
import org.quartz.impl.StdSchedulerFactory;

/**
 *
 * @author Bruno
 */
public class GerenciadorProcesso {
    
	private static  Scheduler sched;
	
    public static void agendar(){
 
        try {
            SchedulerFactory schedFact = new StdSchedulerFactory();
            sched = schedFact.getScheduler();
            sched.start();
            JobDetail job = JobBuilder.newJob(MontarPerfil.class)
                .withIdentity("Montar Perfil", "Perfil")
                .build();
            Trigger trigger = TriggerBuilder
                .newTrigger()
                .withIdentity("5 minutos", "Perfil")
                .withSchedule(CronScheduleBuilder.cronSchedule("0 0/5 * * * ?"))
                .build();
             sched.scheduleJob(job, trigger);
        } catch (Exception e) {
            System.out.println("erro");
            e.printStackTrace();
        }
        
    }
    
    public static void finalizarAgendamento(){
    	 
        try {
            SchedulerFactory schedFact = new StdSchedulerFactory();
            sched = schedFact.getScheduler();
            sched.shutdown();
         } catch (Exception e) {
            System.out.println("erro");
            e.printStackTrace();
        }
        
    }
    
}
